﻿@model LuShanTea.Admin.Web.Models.GoodEditGetModel
@{
    ViewBag.Title = "AddNew";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<style>
    /*日期的css开始*/
    body {
        padding: 20px;
    }

    .demo-input {
        padding-left: 10px;
        height: 38px;
        min-width: 262px;
        line-height: 38px;
        border: 1px solid #e6e6e6;
        background-color: #fff;
        border-radius: 2px;
    }

    .demo-footer {
        padding: 50px 0;
        color: #999;
        font-size: 14px;
    }

        .demo-footer a {
            padding: 0 5px;
            color: #01AAED;
        }
    /*日期的css结束*/
</style>

<!--获取日期js-->
<script src="~/common/layui/laydate.js"></script>
<script>
    lay('#version').html('-v' + laydate.v);

    //执行一个laydate实例
    laydate.render({
        elem: '#test1' //指定元素
    });
</script>
<!--获取生产日期结束-->


<section class="layui-larry-box">
    <div class="larry-personal">
        <header class="larry-personal-tit">
            <span>添加商品属性</span>
        </header><!-- /header -->

        <div class="larry-personal-body clearfix">
            <form class="layui-form col-lg-5" action="" method="post">
                <input type="hidden" name="Id" value="@Model.Good.Id" />
                <div class="layui-form-item">
                    <label class="layui-form-label">商品名称</label>
                    <div class="layui-input-block">
                        <input type="text" lay-verify="required" value="@Model.Good.Name" lay-verify="required" name="Name" autocomplete="off" class="layui-input" placeholder="请输入商品名称">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">商品价格</label>
                    <div class="layui-input-block">
                        <input type="text" lay-verify="required" value="@Model.Good.Price" lay-verify="required" name="Price" autocomplete="off" class="layui-input" placeholder="请输入价格">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">商品原始价格</label>
                    <div class="layui-input-block">
                        <input type="text" lay-verify="required" value="@Model.Good.PrePrice" lay-verify="required" name="PrePrice" autocomplete="off" class="layui-input" placeholder="请输入商品原始价格">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">商品重量</label>
                    <div class="layui-inline">
                        <input type="text" lay-verify="required" value="@Model.Good.Weight" name="Weight" lay-verify="required" autocomplete="off" class="layui-input " placeholder="请输入管理员昵称">
                    </div>
                    <div class="layui-inline">
                        <select name="weightUnit"  class="newsLook" lay-filter="browseLook">
                            <option value="0">Kg</option>
                            <option value="1">g</option>
                        </select>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">商品数量</label>
                    <div class="layui-input-block">
                        <input lay-verify="required" value="@Model.Good.TotalCount" type="text" name="TotalCount" autocomplete="off" class="layui-input" placeholder="请输入数量">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">商品已销售量</label>
                    <div class="layui-input-block">
                        <input lay-verify="required" value="@Model.Good.Selled" type="text" name="Selled" autocomplete="off" class="layui-input" placeholder="请输入已销售数量">
                    </div>
                </div>


                <div class="layui-form-item">
                    <label class="layui-form-label">商品类别</label>

                    <div class="layui-inline">
                        @Html.DropDownList("CateGoriesId", new SelectList(Model.Categorys, "Id", "Name", Model.Good.CateGoriesId))
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">包装类型</label>
                    <div class="layui-input-block">
                        @foreach (var pack in Model.Packs)
                        {
                            <input type="checkbox" checked="@Model.Good.PackIds.Contains(pack.Id)" name="PackIds" value="@pack.Id" title="@pack.Name">
                        }
                        
                    </div>
                </div>



                <div class="layui-form-item">
                    <label class="layui-form-label">所属城市</label>

                    <div class="layui-inline">
                        <select id="province" lay-filter="aihao">
                            @foreach (var province in Model.Provinces)
                            {
                                <option value="@province.Id">@province.Name</option>
                            }

                        </select>
                    </div>
                    
                    <div class="layui-inline">
                        <select name="CityId" id="city" class="newsLook" lay-filter="browseLook">
                            @foreach (var city in Model.Citys)
                            {
                                <option value="@city.Id">@city.Name</option>
                                 
                            }

                        </select>
                    </div>
                  </div>

                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">商品描述</label>
                    <div class="layui-input-block">
                        <textarea name="Descible" placeholder="既然选择了远方，便只顾风雨兼程；路漫漫其修远兮，吾将上下而求索" value="" class="layui-textarea">@Model.Good.Descible</textarea>
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit="" lay-filter="editBtn">立即提交</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</section>



@section FooterScript{

    <script src="~/common/layui/layui.js"></script>
    <script type="text/javascript">
        $(function () {

          
        })
        // 定义一个渲染方法
        function renderForm() {
            layui.use('form', function () {
                var form = layui.form();//高版本建议把括号去掉，有的低版本，需要加()
                form.render();
            });
        }

        //<!--文件上传js-- >
        layui.use(['form', 'upload'], function () {
            var form = layui.form();
            layui.upload({
                url: '',//上传接口
                success: function (res) {
                    //上传成功后的回调
                    console.log(res)
                }
            });

        });

        // 省市联级查询
        layui.use(['jquery', 'layer', 'element', 'laypage', 'form'], function () {
            window.jQuery = window.$ = layui.jquery;
            window.layer = layui.layer;
            var element = layui.element(),
                laypage = layui.laypage;
            var form = layui.form();

            // 省市练级查询
            form.on('select(aihao)', function (data) {
                var provinceId = data.value;
                //layer.msg(provinceId);
                $.ajax({
                    type: "post",
                    url: "/Good/GetCityByProvinceId",
                    data: { provinceId: provinceId },
                    dataType: "Json",
                    success: function (res) {
                        if (res.status == "ok") {
                            $("#city").empty();
                            for (var i = 0; i < res.data.length; i++) {
                                var city = res.data[i];
                                $("#city").append("<option value='" + city.id + "'>" + city.name + "</option>");
                            }
                            renderForm();//表单重新渲染，要不然添加完显示不出来新的option

                        } else {
                            layer.msg('获取失败', { icon: 2, time: 1000 });
                        }
                    },
                    error: function () {
                        layer.msg('发送请求失败', { icon: 2, time: 1000 });
                    }
                })
            });


            //此处的editBtn代码中提交按钮的 lay-filter属性
            form.on("submit(editBtn)", function (data) {

                var index = top.layer.msg('数据提交中，请稍候', { icon: 16, time: false, shade: 0.8 });

                var formData = $(".layui-form").serialize();    //表单数据

                $.ajax({
                    url: "/Good/Edit",
                    method: "post",
                    dataType: "json",
                    data: formData,
                    traditional: true,//这里设置为true
                    success: function (res) {
                        if (res.status == "ok") {
                            layer.msg("添加成功", {
                                icon: 1, time: 1000, end: function () {
                                    top.layer.close(index);
                                    layer.closeAll("iframe");
                                    //刷新父页面
                                    parent.location.reload();
                                }
                            });



                        } else {
                            layer.msg("添加失败:" + res.errorMsg, {
                                icon: 5, time: 2000, end: function () {
                                    top.layer.close(index);
                                    layer.closeAll("iframe");
                                    //刷新父页面
                                    parent.location.reload();
                                }
                            });
                        }
                    },
                    error: function () {
                        layer.msg("网络请求失败", {
                            icon: 5, time: 2000, end: function () {
                                top.layer.close(index);
                                layer.closeAll("iframe");
                                //刷新父页面
                                parent.location.reload();
                            }
                        });
                    }
                });

                return false;
            })
        });
    </script>

}
